/*
 * Toedo
 * Copyright (C) 2009-2010 J. Devauchelle and contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 3 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

package org.toedo.gui.wizards.htmlexport;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.jface.wizard.Wizard;
import org.toedo.controllers.DataController;
import org.toedo.logging.Log;
import org.toedo.model.export.HtmlGenerator;

public class HtmlExportWizard extends Wizard {

	private HtmlExportIntroPage mIntroPage;
	private HtmlExportCssPage mCssPage;
	
	public HtmlExportWizard() {
		super();
		setNeedsProgressMonitor(true);
	}
	
	public void addPages() {
		mIntroPage = new HtmlExportIntroPage();
		addPage(mIntroPage);
		mCssPage = new HtmlExportCssPage();
		addPage(mCssPage);
	}
	
	@Override
	public boolean performFinish() {
		
		HtmlGenerator generator = new HtmlGenerator(DataController.getInstance().getProject(),
				mIntroPage.getFileName(),
				mIntroPage.getIncludeToc(),
				mIntroPage.getIncludeClosedTasks(),
				mCssPage.getIncludeCss(),
				mCssPage.getCustomCssText());
		
		try {
			getContainer().run(true, true, generator);
		} catch (InvocationTargetException e) {
			Log.getInstance(HtmlExportWizard.class).warn("Error in HTML export: InvocationTargetException:" + e.getMessage()); //$NON-NLS-1$
		} catch (InterruptedException e) {
			Log.getInstance(HtmlExportWizard.class).warn("Error in playlist generation: InterruptedException:" + e.getMessage()); //$NON-NLS-1$
		}
		
		return true;
	}

}
